%% @author author

-module(hello_server).
-include("./gen-erl/hello_thrift.hrl").
-export([start/0, handle_function/2, say/1, stop/1]).

debug(Info)->
  io:format("Debug info:~s~n",[Info]).

say(Name)->
  Sentence = "Hello," ++ Name,
  debug(Sentence),
  BinSentence = list_to_binary(Sentence),
  BinSentence.

start()->
  start(9090).

start(Port)->
  Handler = ?MODULE,
  thrift_socket_server:start([{handler, Handler},
    {service, hello_thrift},
    {port, Port},
    {name, hello_server}]).

stop(Server)->
  thrift_socket_server:stop(Server).


handle_function(Function, Args) when is_atom(Function), is_tuple(Args) ->
  case apply(?MODULE, Function, tuple_to_list(Args)) of
    ok -> ok;
    Reply -> {reply, Reply}
  end.